package controller

import (
	usermodel "07demo-gin-mongodb/model"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
)

// selectOne
// @Tags 用户
// @Tag 用户
// @Summary 查询用户
// @Produce  json
// @Param page query int false "页码"
// @Param page_size query int false "每页数量"
// @Success 200 {object} models.TbUser "成功"
// @Router /user/list [get]

//func SelectOneGet(c *gin.Context) {
//	page, _ := strconv.Atoi(c.Query("page"))
//	if page == 0 {
//		page = 1
//	}
//	res, rows, err := usermodel.SelectOne("zhangsan")
//	if err != nil {
//		//c.JSON(http.StatusMovedPermanently, gin.H{"code:": 1, "msg: ": err.Error()})
//		return
//	}
//	c.JSON(http.StatusOK, gin.H{"code": 0, "list": res, "pageTotal": rows})
//	return
//}

func List(c *gin.Context) {
	page, _ := strconv.Atoi(c.Query("page"))
	if page == 0 {
		page = 1
	}
	var list []usermodel.User
	res, rows, err := usermodel.List(list, 1)
	if err != nil {
		//c.JSON(http.StatusMovedPermanently, gin.H{"code:": 1, "msg: ": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 0, "list": res, "pageTotal": rows})
	return
}
